<?php

    function mydate($date)
    {
       $day=substr($date,8,2);
       $mymonth = array('Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ags','Sep','Okt','Nov','Dec');
       $month=substr($date,5,2);
       $year=substr($date,0,4);
       $temp=$day.' '.$mymonth[$month-1].' '.$year;
       return $temp;
    }

    if(!empty($advs))
    {
        echo "<table cellpadding=0 cellspacing=0 style='border:none' class='mytable' >";
            echo "<tr><th width='40px'>ID</th> <th width='260px'>Logo</th><th width='240px'>URL</th><th width='180px'>Perusahaan</th><th width='100px'>Tanggal</th><th width='170px'>Status</th><th width='170px'>Tindakan</th></tr>";
            foreach($advs as $data)
            {
            echo "<tr>";
                echo "<td>".$data['advs']['id']."</td>";
                echo "<td>".$html->link($html->image('../'.$data['advs']['image'],array('class'=>'adv')),$data['advs']['link'],array(),false,false)."</td>";
                echo "<td>".$data['advs']['link']."</td>";
                echo "<td>".$data['employers']['company_name']."</td>";
                echo "<td>".mydate($data['advs']['created'])."</td>";
                echo "<td>";
                if($data['advs']['status']==1)
                { 
                    if($data['advs']['end_date'] < date("Y-m-d") )
                    { echo " Tanggal Kadaluarsa "; }
                    else
                    { echo " Tanggal Diterbitkan "; }
                    echo " <br> ";
                    echo mydate($data['advs']['end_date']); 
                }
                else
                { 
                    if($data['advs']['slip']!='')
                    { 
                        echo " Mengunggu Approval ";
                        echo "<br>";
                        echo $ajax->link('[ Lihat Slip ]',
                                            array('controller'=>'advs','action'=>'slip_admin',$data['advs']['id']),
                                            array('update'=>'slip','class'=>'sky','complete'=>"make_slip();")
                                         );                                                                   
                        echo " ";
                        echo $ajax->link('[ Terbitkan ]',
                                            array('controller'=>'advs','action'=>'approve_admin',$data['advs']['id']),
                                            array('update'=>'result','class'=>'sky','complete'=>"document.getElementById('status').value=1;")
                                         );                                                                   
                        
                        
                    }
                    else
                    { echo " Menunggu Pembayaran "; }
                }
                echo "</td>";
                echo "<td>";
                echo $ajax->link('[ Edit ]',
                                    array('controller'=>'advs','action'=>'edit_admin',$data['advs']['id']),
                                    array('update'=>'slip','class'=>'sky','complete'=>"make_slip();document.getElementById('status').value=1;")
                                 );            
                echo " ";
                echo $ajax->link( '[ Hapus ]', 
                        array('controller' => 'advs', 'action' => 'delete_admin',$data['advs']['id']),
                        array('update' => 'result','class'=>'sky'),
                        "Are you sure ?"
                        );                           
                
                echo "</td>";
            echo "</tr>";
            }
            echo "<tr class='end'><td class='end' colspan=8> &nbsp </td></tr>";
        echo "</table>";
    }
    else
    { echo "<span class='red'>Maaf, data tidak tersedia pada kategori yang anda pilih</span>"; }
    echo "<div id='slip'></div>";  
?>